#include "Vector3.h"
#include <math.h>
#include <iostream>
using namespace std;

const Vector3 Vector3::ZERO = Vector3(0,0,0);

Vector3::Vector3(): x(0), y(0), z(0) {}

Vector3::Vector3(float inx, float iny, float inz): x(inx), y(iny), z(inz){
}

float Vector3::getMagnitude(){
	return (sqrt(x*x + y*y + z*z));
}
void Vector3::normalize(){
	float mag = getMagnitude();
	if (mag == 0){
		return;
	}
	x /= mag;
	y /= mag;
	z /= mag;
}

Vector3 Vector3::crossProduct(const Vector3& v) const{
	return Vector3((y * v.z) - (z * v.y),
				   -((x*v.z) - (z*v.x)),
				  (x * v.y) - (y * v.x));
}

Vector3 Vector3::operator-(){
	return Vector3(-x,-y,-z);
}

Vector3 Vector3::operator-(const Vector3 &v) const{
	return Vector3(x - v.x, y - v.y, z - v.z);
}

Vector3 Vector3::operator+(const Vector3& v) const{
	return Vector3(x + v.x, y + v.y, z + v.z);
}

Vector3 Vector3::operator/(const float d) const{
	return Vector3(x / d, y / d, z / d);
}

Vector3 Vector3::operator*(const float m) const{
	return Vector3(x * m, y * m, z * m);
}

float Vector3::operator*(const Vector3& v) const{
	return (x * v.x) + (y * v.y) + (z * v.z);
}

float& Vector3::operator[] (unsigned i){
	switch(i){
		case 0:
			return x;
		case 1:
			return y;
		case 2:
			return z;
		default:
			throw -1;
	}
}